﻿package mortal.game.view.heroArena.view
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.control.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.heroArena.util.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class HeroArenaResultWin extends ResultBaseWindow
    {
        private var _roleName1:GTextFiled;
        private var _roleInfo1:GTextFiled;
        private var _roleName2:GTextFiled;
        private var _roleInfo2:GTextFiled;
        private var _tipInfo:GImageBitmap;
        private var _gainPoint:GTextFiled;
        private var _gainGold:GTextFiled;
        private var _totalPoint:BitmapNumberText;
        private var _tips:GTextFiled;
        private var _goldShopLink:GButton;
        private var _lookRankLink:GButton;
        private var _headSpr:GSprite;
        private var _playerInfo1:SArenaBasePlayer;
        private var _playerInfo2:SArenaBasePlayer;
        private static var _instance:HeroArenaResultWin;

        public function HeroArenaResultWin(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tipInfo = UIFactory.gImageBitmap(ImagesConst.HeroArenaTeamFailTxt, 162 - 42, 55 - 6, this);
            this._headSpr = UICompomentPool.getUICompoment(GSprite);
            this._headSpr.x = 229 - 30 + 5;
            this._headSpr.y = 54 - 14;
            this.addChild(this._headSpr);
            this._roleName1 = UIFactory.gTextField("", 0, 0, 100, 20, this._headSpr);
            this._roleName1.htmlText = HTMLUtil.addLink("", GlobalStyle.colorLv);
            this._roleName1.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this._roleName1.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._roleName1.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._roleInfo1 = UIFactory.gTextField("", 87, 0, 153 + 17, 20, this._headSpr);
            this._roleName2 = UIFactory.gTextField("", 0, 22 - 2, 100, 20, this._headSpr);
            this._roleName2.htmlText = HTMLUtil.addLink("", GlobalStyle.colorLv);
            this._roleName2.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this._roleName2.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._roleName2.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._roleInfo2 = UIFactory.gTextField("", 87, 22 - 2, 153 + 17, 20, this._headSpr);
            this.pushUIToDisposeVec(UIFactory.bg(254 - 20, 87 - 3, 231, 100, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ArenaResultTextBg, 254 - 20 + 5, 87 - 2 + 1, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ArenaResultText, 254 + 67, 90 - 3, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41563), 254 - 20 + 5 + 59, 86 + 43 - 9, 85, 25, this, GlobalStyle.textFormatPutong.setSize(14)));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41564), 254 - 20 + 5 + 59 - 25 - 17, 86 + 43 + 23 - 9, 113, 25, this, GlobalStyle.textFormatPutong.setSize(14)));
            this._gainPoint = UIFactory.gTextField("", 254 - 20 + 5 + 130, 86 + 43 - 9, 63, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this._gainGold = UIFactory.gTextField("", 254 - 20 + 5 + 130, 86 + 43 + 23 - 9, 63, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41565), 254 - 20 + 62 - 17 - 14, 84 + 110 - 3, 114, 26, this, GlobalStyle.textFormatHuang.setSize(16)));
            this._totalPoint = UIFactory.bitmapNumberText(254 - 20 + 126 - 17 + 22, 84 + 110 + 4 - 2, "WizardNum.png", 13, 17, -1, this);
            this._totalPoint.text = "";
            this._tips = UIFactory.gTextField("", 254 - 20 - 45, 84 + 179, 200, 20, this);
            this._tips.htmlText = HTMLUtil.addColor(Language.getString(41566), GlobalStyle.colorLv) + HTMLUtil.addColor(Language.getString(41567), GlobalStyle.colorHuang2);
            this._goldShopLink = UIFactory.gButton(Language.getString(41568), 254 - 20 + 165, 84 + 179, 65, 20, this, "GreenLinkButton");
            this._lookRankLink = UIFactory.gButton(Language.getString(41569), 254 - 20 + 235, 84 + 179, 75, 20, this, "GreenLinkButton");
            this._goldShopLink.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._lookRankLink.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.updateSize();
            return;
        }// end function

        public function updateArenaResult() : void
        {
            var _loc_2:SArenaPlayer = null;
            var _loc_3:SArenaPlayer = null;
            var _loc_4:SArenaPlayer = null;
            var _loc_5:SArenaPlayer = null;
            var _loc_6:SArena2v2Team = null;
            var _loc_7:SEntityId = null;
            var _loc_8:String = null;
            var _loc_9:String = null;
            var _loc_1:* = Cache.instance.heroArena.sArenaPlayerResult;
            if (_loc_1)
            {
                _loc_2 = _loc_1.result[0];
                _loc_3 = _loc_1.result[1];
                if (!(_loc_2 && _loc_3))
                {
                    return;
                }
                _loc_6 = Cache.instance.heroArena.myTeamInfo;
                _loc_7 = _loc_6 == null ? (null) : (_loc_6.teamId);
                if (EntityUtil.equal(_loc_2.entityId, _loc_7))
                {
                    _loc_4 = _loc_2;
                    _loc_5 = _loc_3;
                }
                else
                {
                    _loc_4 = _loc_3;
                    _loc_5 = _loc_2;
                }
                this._playerInfo1 = _loc_5.playerInfos[0];
                this._playerInfo2 = _loc_5.playerInfos[1];
                if (_loc_4.isFail)
                {
                    resultType = ResultBaseWindow.showFail;
                    this._tipInfo.imgUrl = ImagesConst.HeroArenaTeamFailTxt;
                }
                else
                {
                    resultType = ResultBaseWindow.showSuccess;
                    this._tipInfo.imgUrl = ImagesConst.HeroArenaTeamWinTxt;
                }
                if (this._playerInfo1)
                {
                    this._roleName1.htmlText = HTMLUtil.addLink(this._playerInfo1.name, GlobalStyle.colorLv);
                    _loc_8 = GameDefConfig.instance.getECareerNameAddColoer(this._playerInfo1.career);
                    this._roleInfo1.htmlText = "[Lv." + this._playerInfo1.level + "/" + _loc_8 + "/" + Language.getString(41570) + this._playerInfo1.combat + "]";
                    this._roleInfo1.x = this._roleName1.x + this._roleName1.textWidth + 2;
                }
                if (this._playerInfo2)
                {
                    this._roleName2.htmlText = HTMLUtil.addLink(this._playerInfo2.name, GlobalStyle.colorLv);
                    _loc_9 = GameDefConfig.instance.getECareerNameAddColoer(this._playerInfo2.career);
                    this._roleInfo2.htmlText = "[Lv." + this._playerInfo2.level + "/" + _loc_9 + "/" + Language.getString(41570) + this._playerInfo2.combat + "]";
                    this._roleInfo2.x = this._roleName2.x + this._roleName2.textWidth + 2;
                }
                if (_loc_4.markInBattle > 0)
                {
                    this._gainPoint.htmlText = HTMLUtil.addColor("+" + _loc_4.markInBattle, GlobalStyle.colorLv);
                }
                else
                {
                    this._gainPoint.htmlText = HTMLUtil.addColor("" + _loc_4.markInBattle, GlobalStyle.colorHong);
                }
                if (_loc_4.goldNote > 0)
                {
                    this._gainGold.htmlText = HTMLUtil.addColor("+" + _loc_4.goldNote, GlobalStyle.colorHuang2);
                }
                else
                {
                    this._gainGold.htmlText = HTMLUtil.addColor("" + _loc_4.goldNote, GlobalStyle.colorHong);
                }
                this._totalPoint.text = "" + _loc_4.mark;
            }
            return;
        }// end function

        override protected function addTypeBg() : void
        {
            _typeBg = UIFactory.gImageBitmap(ImagesConst.ResultWinTypeBg, 0, 0, this, this.onTypeBgLoadCompl);
            return;
        }// end function

        private function onTypeBgLoadCompl() : void
        {
            _typeBg.height = 48;
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (_enterBtn)
            {
            }
            if (_enterBtn)
            {
                _enterBtn.y = _enterBtn.y - 18;
            }
            return;
        }// end function

        override protected function addContentBg() : void
        {
            return;
        }// end function

        override protected function setContentBgSize(param1:int, param2:int) : void
        {
            return;
        }// end function

        private function onLinkClickHandler(event:Event) : void
        {
            var _loc_3:SEntityId = null;
            var _loc_2:* = (event.target as GTextFiled).text;
            if (this._playerInfo1 && this._playerInfo2)
            {
                if (_loc_2 == this._playerInfo1.name)
                {
                    _loc_3 = this._playerInfo1.entityId;
                }
                if (_loc_2 == this._playerInfo2.name)
                {
                    _loc_3 = this._playerInfo2.entityId;
                }
            }
            if (_loc_3)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, _loc_3));
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            if (event.target == this._goldShopLink)
            {
                _loc_2 = HeroArenaUtil.getArenaMoneyByLevel(HeroArenaController.HeroArenaLevel).shopIndex;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallChangeTabIndex, [ShopUtil.ShopTabArena2v2, _loc_2]));
            }
            if (event.target == this._lookRankLink)
            {
                GameController.ranking.view.show();
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function enterBtnClickHandler(event:MouseEvent) : void
        {
            if (GameMapUtil.curMapState.isHeroArenaMap)
            {
                GameProxy.copy.leaveCopy();
            }
            hide();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.layer.setTop(this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._roleName1.dispose();
            this._roleName1 = null;
            this._roleInfo1.dispose();
            this._roleInfo1 = null;
            this._roleName2.dispose();
            this._roleName2 = null;
            this._roleInfo2.dispose();
            this._roleInfo2 = null;
            this._tipInfo.dispose();
            this._tipInfo = null;
            this._gainPoint.dispose();
            this._gainPoint = null;
            this._gainGold.dispose();
            this._gainGold = null;
            this._totalPoint.dispose();
            this._totalPoint = null;
            this._tips.dispose();
            this._tips = null;
            this._goldShopLink.dispose();
            this._goldShopLink = null;
            this._lookRankLink.dispose();
            this._lookRankLink = null;
            this._headSpr.dispose();
            this._headSpr = null;
            this._playerInfo1 = null;
            this._playerInfo2 = null;
            return;
        }// end function

        public static function get instance() : HeroArenaResultWin
        {
            if (_instance == null)
            {
                _instance = new HeroArenaResultWin;
            }
            return _instance;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
